from pydantic import BaseModel, Field
from datetime import datetime
from typing import Optional
from .drone import DroneSchema

# 基础模型
class TaskDroneBase(BaseModel):
    task_id: int = Field(..., description="任务ID")
    drone_id: int = Field(..., description="无人机ID")
    is_primary: bool = Field(False, description="是否为主用飞机")
    status: str = Field("assigned", description="状态：assigned, active, completed, failed")
    notes: Optional[str] = Field(None, description="备注信息", max_length=255)

# 创建模型
class TaskDroneCreate(TaskDroneBase):
    pass

# 更新模型
class TaskDroneUpdate(BaseModel):
    is_primary: Optional[bool] = None
    status: Optional[str] = None
    notes: Optional[str] = Field(None, max_length=255)

# 响应模型
class TaskDroneResponse(TaskDroneBase):
    id: int
    assigned_at: datetime
    start_time: Optional[datetime]
    end_time: Optional[datetime]
    
    # 关联信息
    task_name: Optional[str] = None
    drone: Optional[DroneSchema] = None
    
    class Config:
        from_attributes = True

class TaskDroneSchema(BaseModel):
    """任务关联的无人机信息响应模型"""
    id: int = Field(..., description="关联ID")
    task_id: int = Field(..., description="任务ID")
    drone_id: int = Field(..., description="无人机ID")
    is_primary: bool = Field(False, description="是否为主用无人机")
    drone: Optional[DroneSchema] = Field(None, description="无人机信息")
    
    class Config:
        from_attributes = True